package algorithms.que12;

import edu.princeton.cs.algs4.Interval1D;
import edu.princeton.cs.algs4.StdRandom;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @功能
 * @创建时间 2020/6/21
 */
public class Interval1D2 {
    public static void main(String[] args) {
       createInterval(10);
    }
    public static void createInterval(Integer n){
        List<Interval1D> w = new ArrayList<>();
        Random random = new Random();
        for(int i=0;i<n;i++) {
            //lo和·hi不能相等
            double lo = StdRandom.uniform(4);
            double hi = StdRandom.uniform(5)+lo;
            System.out.println(lo);
            Interval1D a = new Interval1D(lo,hi);
            w.add(a);
        }
       compare(w);
    }
    public static void compare(List<Interval1D> w){
        int count=0;
        int i=0;
        while (i!=w.size()-1){
            for (int j=i;j<w.size()-1;j++){
                if(w.get(i).intersects(w.get(j+1))){
      //              System.out.println(count);
                    count++;
                }
            }
            i++;

        }
        System.out.println(count);
    }
}
